<template>
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="机器人名称" prop="robot_name">
        <el-input v-model="queryParams.robot_name" placeholder="请输入机器人名称" clearable @keyup.enter.native="handleQuery"
          size="small" />
      </el-form-item>
      <el-form-item label="告警描述" prop="alarmDesc">
        <el-input v-model="queryParams.alarmDesc" placeholder="请输入告警描述" clearable @keyup.enter.native="handleQuery"
          size="small" />
      </el-form-item>
      <el-form-item label="告警时间">
        <el-date-picker v-model="queryParams.create_times" style="width: 215px" value-format="yyyy-MM-dd"
          format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
    </el-row>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['robot:alarm:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--数据列表区域-->
    <el-table v-loading="loading" :data="listAlarmData" @selection-change="handleSelectionChange"
      :cell-style="{ borderColor: 'rgb(1 5 43)' }" :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="序号" type="index" align="center" prop="id" width="100" />-->
      <!--<el-table-column label="机器人编号" align="center" prop="robot_num" width="160" />-->
      <el-table-column label="机器人名称" align="center" prop="robot_name" />
      <!--<el-table-column label="参数简称" align="center" prop="param_en" width="150" />
      <el-table-column label="参数名称" align="center" prop="param_name" width="160" />-->
      <el-table-column label="告警描述" align="center" prop="alarminfo" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="告警值" align="center" prop="alarmValue" width="90" />-->
      <el-table-column label="告警时间" align="center" prop="alarmtime" />
      <el-table-column label="状态" align="center" width="280" prop="state">
        <template slot-scope="scope">
          <el-button class="btn1" size="mini" v-if="scope.row.state == 0"
            @click="changeStatus(scope.row)">未处理</el-button>
          <el-button class="btn2" size="mini" v-if="scope.row.state == 1">已处理</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['robot:alarm:removedata']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--列表分页区域-->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);" />
  </div>
</template>
<script>
import "@/assets/styles/robt-bg.css";
import { listAlarmData , ChangeState } from "@/api/robot/alarm/alarmData/alarm";
import { delsAlarm } from "@/api/robot/alarm/alarmSet/alarm";

export default {
  name: "AlarmData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //初始化列表数据
      listAlarmData: [],
      // 总条数
      total: 0,
      //查询条件区域------初始化站点下拉列表数据
      siteListselc: [],
      //查询条件区域------工艺体下拉列表数据
      processbodyListc: [],
      //查询条件区域--机器人下拉表格数据
      robotconfigListgyt: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        site_name: undefined,
        process_name: undefined,
        robot_name: undefined,
        create_times: [this.dealWithTime(new Date()), this.dealWithTime(new Date())],
        alarmDesc: undefined
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList(); /** 初始化告警数据列表 */
  },
  methods: {
    changeStatus(row) {
      ChangeState(row.id).then(response => {
        if (response.code == 200) {
          this.getList()
        }
      })
    },
    //日期格式化
    dealWithTime(date) {
      let Y = date.getFullYear()
      let M = date.getMonth() + 1 - 0 >= 10 ? Number(date.getMonth()) + 1 : '0' + (Number(date.getMonth()) + 1)
      let D = date.getDate() > 10 ? date.getDate() : "0" + date.getDate();
      return Y + '-' + M + '-' + D
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      //this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function() {
      this.$modal.confirm('是否确认删除选中的数据项？').then(function () {
        return delsAlarm(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    }, /**初始化告警数据列表*/
    getList() {
      this.loading = true;
      listAlarmData(this.queryParams).then(response => {
        this.listAlarmData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },// 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },// 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },/** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.create_times = [this.dealWithTime(new Date()), this.dealWithTime(new Date())];
      this.queryParams.site_name = null;
      this.queryParams.process_name = null;
      this.queryParams.robot_name = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
  }
};
</script>
<style lang="scss" scoped>

.btn1 {
  width: 80px;
  height: 25px;
  color: #fff;
  background: linear-gradient(0deg, #4C0820, #0D1538);
  border-radius: 2px;
  border: 1px solid #942028;
}

.btn2 {
  width: 80px;
  height: 25px;
  color: #848484;
  background: linear-gradient(0deg, #0D1538, #444545);
  border-radius: 2px;
  border: 1px solid #4B4B4B;
}
</style>
